home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 223_01 / itoab.c < prev    next >
Text File  |  1980-01-01  |  768b  |  24 lines

  1. #define NOCCARGC  /* no argument count passing */
  2. /*
  3. ** itoab(n,s,b) - Convert "unsigned" n to characters in s using base b.
  4. **                NOTE: This is a non-standard function.
  5. */
  6.  
  7.    static char *ptr;
  8.    static int lowbit;
  9.  
  10. itoab(n, s, b) int n; char *s; int b; {
  11.   ptr = s;
  12.   b >>= 1;
  13.   do {
  14.     lowbit = n & 1;
  15.     n = (n >> 1) & 32767;
  16.     *ptr = ((n % b) << 1) + lowbit;
  17.     if(*ptr < 10) *ptr += '0'; else *ptr += 55;
  18.     ++ptr;
  19.     } while(n /= b);
  20.   *ptr = 0;
  21.   reverse (s);
  22.   }
  23.  
  24.